{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0ba6b56b-ac3d-417f-b075-b8a503f52fed",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load model directly\n",
    "from transformers import AutoTokenizer, AutoModelForSequenceClassification\n",
    "\n",
    "tokenizer = AutoTokenizer.from_pretrained(\"lxyuan/distilbert-base-multilingual-cased-sentiments-student\", cache_dir=\"/root/autodl-tmp/hf/hub/\")\n",
    "model = AutoModelForSequenceClassification.from_pretrained(\"lxyuan/distilbert-base-multilingual-cased-sentiments-student\", cache_dir=\"/root/autodl-tmp/hf/hub/\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3b339598-16b9-4b85-aff8-9ffe2bae4ddf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'input_ids': tensor([[  101,   146, 16138, 10531, 18379, 10111,   177, 10894, 34481, 10271,\n",
      "         13123, 10111, 13123,   106,   102]]), 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])}\n"
     ]
    }
   ],
   "source": [
    "text = \"I love this movie and i would watch it again and again!\"\n",
    "token_ids = tokenizer(text, truncation=True, padding=True, return_tensors='pt')\n",
    "print(token_ids)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "451a0114-ed7f-4110-866c-930427df9efd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[ 2.8025, -1.2501, -1.7769]])\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'positive': 0.9731044769287109}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "\n",
    "with torch.no_grad():\n",
    "    logits = model(**token_ids).logits\n",
    "print(logits)\n",
    "preds = torch.softmax(logits, dim=-1)\n",
    "id2lang = model.config.id2label\n",
    "vals, idxs = torch.max(preds, dim=1)\n",
    "{id2lang[k.item()]: v.item() for k, v in zip(idxs, vals)}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "9e3cbc14-0349-47f4-b835-a2689690d9bf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'input_ids': tensor([[ 101, 3976, 2187, 3198, 3767, 8595, 2458,  102],\n",
      "        [ 101, 3976, 2187, 3198, 3767, 3204, 6824,  102]]), 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 1, 1],\n",
      "        [1, 1, 1, 1, 1, 1, 1, 1]])}\n"
     ]
    }
   ],
   "source": [
    "text = [\n",
    "    \"我今天很高兴\",\n",
    "    \"我今天很失落\"\n",
    "]\n",
    "token_ids = tokenizer(text, truncation=True, padding=True, return_tensors='pt')\n",
    "print(token_ids)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e4618abe-3f7f-4882-b89e-ff7ce195e2fd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[ 3.1015, -1.1591, -2.1024],\n",
      "        [-1.8359, -0.1215,  2.3418]])\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'positive': 0.9807682633399963, 'negative': 0.9086870551109314}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "with torch.no_grad():\n",
    "    logits = model(**token_ids).logits\n",
    "print(logits)\n",
    "\n",
    "preds = torch.softmax(logits, dim=-1)\n",
    "id2lang = model.config.id2label\n",
    "vals, idxs = torch.max(preds, dim=1)\n",
    "{id2lang[k.item()]: v.item() for k, v in zip(idxs, vals)}\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "be7a1642-f65c-4049-abda-923ff460d9c5",
   "metadata": {
    "tags": []
   },
   "source": [
    "### NER(命名实体识别-Named Entity Recognition)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "c4f2cf17-2791-4de6-9921-b0e5c3e81adc",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Some weights of the model checkpoint at dslim/bert-base-NER were not used when initializing BertForTokenClassification: ['bert.pooler.dense.bias', 'bert.pooler.dense.weight']\n",
      "- This IS expected if you are initializing BertForTokenClassification from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).\n",
      "- This IS NOT expected if you are initializing BertForTokenClassification from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'entity': 'B-PER', 'score': 0.9990139, 'index': 4, 'word': 'Wolfgang', 'start': 11, 'end': 19}, {'entity': 'B-LOC', 'score': 0.999645, 'index': 9, 'word': 'Berlin', 'start': 34, 'end': 40}]\n"
     ]
    }
   ],
   "source": [
    "from transformers import AutoTokenizer, AutoModelForTokenClassification\n",
    "from transformers import pipeline\n",
    "\n",
    "tokenizer = AutoTokenizer.from_pretrained(\"dslim/bert-base-NER\", cache_dir=\"/root/autodl-tmp/hf/hub/\")\n",
    "model = AutoModelForTokenClassification.from_pretrained(\"dslim/bert-base-NER\", cache_dir=\"/root/autodl-tmp/hf/hub/\")\n",
    "\n",
    "nlp = pipeline(\"ner\", model=model, tokenizer=tokenizer)\n",
    "example = \"My name is Wolfgang and I live in Berlin\"\n",
    "\n",
    "ner_results = nlp(example)\n",
    "print(ner_results)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5ba3d64c-1e7b-43a5-a4cc-723361676876",
   "metadata": {},
   "source": [
    "### POS(词性标注-Part-of-Speech)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "6aef06df-696d-482f-b59c-ec24e32bdcb2",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Asking to truncate to max_length but no maximum length is provided and the model has no predefined maximum length. Default to no truncation.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[{'entity': 'conj',\n",
       "  'score': 0.995174,\n",
       "  'index': 1,\n",
       "  'word': '▁Ale',\n",
       "  'start': 0,\n",
       "  'end': 3},\n",
       " {'entity': 'adv',\n",
       "  'score': 0.9959913,\n",
       "  'index': 2,\n",
       "  'word': '▁dzisiaj',\n",
       "  'start': 4,\n",
       "  'end': 11},\n",
       " {'entity': 'fin',\n",
       "  'score': 0.99789447,\n",
       "  'index': 3,\n",
       "  'word': '▁',\n",
       "  'start': 12,\n",
       "  'end': 13},\n",
       " {'entity': 'fin',\n",
       "  'score': 0.9971215,\n",
       "  'index': 4,\n",
       "  'word': 'leje',\n",
       "  'start': 12,\n",
       "  'end': 16}]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from transformers import AutoTokenizer, AutoModelForTokenClassification\n",
    "from transformers import pipeline\n",
    "\n",
    "tokenizer = AutoTokenizer.from_pretrained(\"wkaminski/polish-roberta-base-v2-pos-tagging\", cache_dir=\"/root/autodl-tmp/hf/hub/\")\n",
    "model = AutoModelForTokenClassification.from_pretrained(\"wkaminski/polish-roberta-base-v2-pos-tagging\", cache_dir=\"/root/autodl-tmp/hf/hub/\")\n",
    "\n",
    "nlp = pipeline(\"token-classification\", model=model, tokenizer=tokenizer)\n",
    "nlp(\"Ale dzisiaj leje\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d2a7f3e7-7787-4efa-801c-14621a5fc9b9",
   "metadata": {},
   "source": [
    "### Question Answering"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "18b55fbf-eb5f-43c6-a304-6d9809e77aa7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'score': 0.48712846636772156, 'start': 321, 'end': 323, 'answer': '白樺'}\n"
     ]
    }
   ],
   "source": [
    "from transformers import BertTokenizerFast, BertForQuestionAnswering, pipeline\n",
    "\n",
    "\n",
    "model_name = \"HankyStyle/Question-Answering-for-Argriculture\"\n",
    "tokenizer = BertTokenizerFast.from_pretrained(model_name, cache_dir=\"/root/autodl-tmp/hf/hub/\", local_files_only=True)\n",
    "model = BertForQuestionAnswering.from_pretrained(model_name, cache_dir=\"/root/autodl-tmp/hf/hub/\", local_files_only=True)\n",
    "\n",
    "\n",
    "nlp = pipeline('question-answering', model=model, tokenizer=tokenizer)\n",
    "QA_input = {\n",
    "    'question': '哪一種植物在根據綜合主成分分析表明可以促進枯落葉養分釋放?',\n",
    "    'context': '以黃土高原主要造林樹種落葉松(Larix principis-rupprechtii)及其他擬混雜的10個樹種為對象，採集當年枯落葉并以無林荒草地腐殖質層土壤作為分解介質，在室內將落葉松與其他樹種枯落葉單獨或以一定比例混合後裝入尼龍網袋並埋入盛土培養缽中，進行恒溫(20~25℃)恒濕(50%田間持水量)下連續345 d分解培養試驗。結果表明：枯落葉單獨分解時，大量元素整體上較微量元素容易釋出。除C和 N外，其他元素釋出速率與其初始含量無顯著相關關係(C為負相關，N正相關)。根據綜合主成分分析表明，與落葉松枯落葉混合分解總體上明顯促進養分釋放的樹種為白榆(Ulmus pumila)和油松(Pinus tabulaeformis)，其次為白樺(Betula platyphylla)；總體上明顯抑制養分釋放的樹種為側柏(Platycladus orientalis)和刺槐(Robinia pseudoacacia)，其次為小葉楊(Populus simonii)。能夠促進枯落葉養分釋放的樹種將是選擇與落葉松混雜樹種時首先考慮的物種。'\n",
    "}\n",
    "res = nlp(QA_input)\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d4f7600b-7b04-45e0-a3da-d1f3e301c7f4",
   "metadata": {},
   "source": [
    "### Summarization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "5c363ba0-7959-4a51-bffe-bb477de17470",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "包头警方发布一起利用AI实施电信诈骗典型案例:法人代表10分钟内被骗430万元\n"
     ]
    }
   ],
   "source": [
    "from transformers import MT5ForConditionalGeneration, T5Tokenizer\n",
    "\n",
    "legacy=False\n",
    "model = MT5ForConditionalGeneration.from_pretrained(\"heack/HeackMT5-ZhSum100k\", cache_dir=\"/root/autodl-tmp/hf/hub/\", local_files_only=True)\n",
    "tokenizer = T5Tokenizer.from_pretrained(\"heack/HeackMT5-ZhSum100k\", cache_dir=\"/root/autodl-tmp/hf/hub/\", local_files_only=True)\n",
    "\n",
    "chunk = \"\"\"\n",
    "财联社5月22日讯，据平安包头微信公众号消息，近日，包头警方发布一起利用人工智能（AI）实施电信诈骗的典型案例，福州市某科技公司法人代表郭先生10分钟内被骗430万元。\n",
    "4月20日中午，郭先生的好友突然通过微信视频联系他，自己的朋友在外地竞标，需要430万保证金，且需要公对公账户过账，想要借郭先生公司的账户走账。\n",
    "基于对好友的信任，加上已经视频聊天核实了身份，郭先生没有核实钱款是否到账，就分两笔把430万转到了好友朋友的银行卡上。郭先生拨打好友电话，才知道被骗。骗子通过智能AI换脸和拟声技术，佯装好友对他实施了诈骗。\n",
    "值得注意的是，骗子并没有使用一个仿真的好友微信添加郭先生为好友，而是直接用好友微信发起视频聊天，这也是郭先生被骗的原因之一。骗子极有可能通过技术手段盗用了郭先生好友的微信。幸运的是，接到报警后，福州、包头两地警银迅速启动止付机制，成功止付拦截336.84万元，但仍有93.16万元被转移，目前正在全力追缴中。\n",
    "\"\"\"\n",
    "inputs = tokenizer.encode(\"summarize: \" + chunk, return_tensors='pt', max_length=512, truncation=True)\n",
    "summary_ids = model.generate(inputs, max_length=150, num_beams=4, length_penalty=1.5, no_repeat_ngram_size=2)\n",
    "summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)\n",
    "\n",
    "print(summary)\n",
    "\n",
    "# 包头警方发布一起利用AI实施电信诈骗典型案例:法人代表10分钟内被骗430万元\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2043385f-c79e-4482-9d99-752e9b515e08",
   "metadata": {},
   "source": [
    "### audio-classification"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b1ec3f29-68ae-48da-9713-262a38a25b10",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'score': 0.9120804071426392, 'label': 'HAPPY'},\n",
       " {'score': 0.05551347881555557, 'label': 'SAD'},\n",
       " {'score': 0.010114066302776337, 'label': 'NEUTRAL'},\n",
       " {'score': 0.007798044942319393, 'label': 'SURPRISE'},\n",
       " {'score': 0.005292875692248344, 'label': 'DISGUST'}]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from transformers import pipeline\n",
    "\n",
    "pipe = pipeline(\"audio-classification\", model=\"shhossain/whisper-tiny-bn-emo\")\n",
    "pipe(\"IEMOCAP_Ses01F_impro04_F000.wav\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e970b728-0015-439a-aeae-7de0b812e099",
   "metadata": {},
   "source": [
    "### automatic-speech-recognition（ASR）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "282e0e14-0fdf-4ae0-8655-e94991ce13e4",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n",
      "Due to a bug fix in https://github.com/huggingface/transformers/pull/28687 transcription using a multilingual Whisper will default to language detection followed by transcription instead of translation to English.This might be a breaking change for your use case. If you want to instead always translate your audio to English, make sure to pass `language='en'`.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'text': ' What Craigslist oh all the internet thing'}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Use a pipeline as a high-level helper\n",
    "from transformers import pipeline\n",
    "\n",
    "pipe = pipeline(\"automatic-speech-recognition\", model=\"openai/whisper-small\")\n",
    "pipe(\"IEMOCAP_Ses01F_impro04_F000.wav\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3cf5e598-a851-451c-b683-95a43d3a0600",
   "metadata": {},
   "source": [
    "### image-classification"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b1d4481a-14f0-4f92-acbd-1a854e40543c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predicted class: Egyptian cat\n"
     ]
    }
   ],
   "source": [
    "from transformers import ViTImageProcessor, ViTForImageClassification\n",
    "from PIL import Image\n",
    "import requests\n",
    "\n",
    "url = 'http://images.cocodataset.org/val2017/000000039769.jpg'\n",
    "image = Image.open(requests.get(url, stream=True).raw)\n",
    "\n",
    "processor = ViTImageProcessor.from_pretrained('google/vit-base-patch16-224')\n",
    "model = ViTForImageClassification.from_pretrained('google/vit-base-patch16-224')\n",
    "\n",
    "inputs = processor(images=image, return_tensors=\"pt\")\n",
    "outputs = model(**inputs)\n",
    "logits = outputs.logits\n",
    "# model predicts one of the 1000 ImageNet classes\n",
    "predicted_class_idx = logits.argmax(-1).item()\n",
    "print(\"Predicted class:\", model.config.id2label[predicted_class_idx])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "83da77e0-baed-4317-b08a-b21c406f5504",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predicted class: golden retriever\n"
     ]
    }
   ],
   "source": [
    "url = \"\"\"https://th.bing.com/th/id/R.4f8a31cc3b8599f047b075ffcc111891?rik=crWlibjh0vLHsQ&riu=http%3a%2f%2fpic1.win4000.com%2fwallpaper%2fe%2f4fcebbf5f0a77.jpg&ehk=HVocTPvgwcxmPL%2fmL7By9tyCkfoQfSuSNrnHYH4j6L4%3d&risl=&pid=ImgRaw&r=0\"\"\"\n",
    "image = Image.open(requests.get(url, stream=True).raw)\n",
    "\n",
    "inputs = processor(images=image, return_tensors=\"pt\")\n",
    "outputs = model(**inputs)\n",
    "logits = outputs.logits\n",
    "# model predicts one of the 1000 ImageNet classes\n",
    "predicted_class_idx = logits.argmax(-1).item()\n",
    "print(\"Predicted class:\", model.config.id2label[predicted_class_idx])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "52291b0d-ac60-4e9e-b7e4-31ecc3993131",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Downloading http://images.cocodataset.org/val2017/000000039769.jpg to '000000039769.jpg'...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 169k/169k [00:00<00:00, 249kB/s]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "image 1/1 /root/autodl-tmp/000000039769.jpg: 480x640 2 cats, 1 couch, 2 remotes, 155.3ms\n",
      "Speed: 5.2ms preprocess, 155.3ms inference, 41.4ms postprocess per image at shape (1, 3, 480, 640)\n",
      "Results saved to \u001b[1mruns/detect/predict\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[ultralytics.engine.results.Results object with attributes:\n",
       " \n",
       " boxes: ultralytics.engine.results.Boxes object\n",
       " keypoints: None\n",
       " masks: None\n",
       " names: {0: 'person', 1: 'bicycle', 2: 'car', 3: 'motorcycle', 4: 'airplane', 5: 'bus', 6: 'train', 7: 'truck', 8: 'boat', 9: 'traffic light', 10: 'fire hydrant', 11: 'stop sign', 12: 'parking meter', 13: 'bench', 14: 'bird', 15: 'cat', 16: 'dog', 17: 'horse', 18: 'sheep', 19: 'cow', 20: 'elephant', 21: 'bear', 22: 'zebra', 23: 'giraffe', 24: 'backpack', 25: 'umbrella', 26: 'handbag', 27: 'tie', 28: 'suitcase', 29: 'frisbee', 30: 'skis', 31: 'snowboard', 32: 'sports ball', 33: 'kite', 34: 'baseball bat', 35: 'baseball glove', 36: 'skateboard', 37: 'surfboard', 38: 'tennis racket', 39: 'bottle', 40: 'wine glass', 41: 'cup', 42: 'fork', 43: 'knife', 44: 'spoon', 45: 'bowl', 46: 'banana', 47: 'apple', 48: 'sandwich', 49: 'orange', 50: 'broccoli', 51: 'carrot', 52: 'hot dog', 53: 'pizza', 54: 'donut', 55: 'cake', 56: 'chair', 57: 'couch', 58: 'potted plant', 59: 'bed', 60: 'dining table', 61: 'toilet', 62: 'tv', 63: 'laptop', 64: 'mouse', 65: 'remote', 66: 'keyboard', 67: 'cell phone', 68: 'microwave', 69: 'oven', 70: 'toaster', 71: 'sink', 72: 'refrigerator', 73: 'book', 74: 'clock', 75: 'vase', 76: 'scissors', 77: 'teddy bear', 78: 'hair drier', 79: 'toothbrush'}\n",
       " obb: None\n",
       " orig_img: array([[[ 56,  25, 140],\n",
       "         [ 67,  25, 144],\n",
       "         [ 73,  24, 146],\n",
       "         ...,\n",
       "         [ 38,  16,  94],\n",
       "         [ 39,  13, 107],\n",
       "         [ 33,  10, 102]],\n",
       " \n",
       "        [[ 57,  22, 138],\n",
       "         [ 49,  26, 142],\n",
       "         [ 48,  20, 139],\n",
       "         ...,\n",
       "         [ 36,  11, 103],\n",
       "         [ 42,  17, 115],\n",
       "         [ 31,  13,  96]],\n",
       " \n",
       "        [[ 42,  22, 135],\n",
       "         [ 59,  33, 150],\n",
       "         [ 53,  23, 142],\n",
       "         ...,\n",
       "         [ 32,   8, 103],\n",
       "         [ 39,  19, 108],\n",
       "         [ 26,  10,  93]],\n",
       " \n",
       "        ...,\n",
       " \n",
       "        [[190, 100, 237],\n",
       "         [196,  84, 225],\n",
       "         [203,  96, 236],\n",
       "         ...,\n",
       "         [131,  47, 171],\n",
       "         [144,  62, 181],\n",
       "         [110,  28, 147]],\n",
       " \n",
       "        [[221,  84, 230],\n",
       "         [213,  80, 226],\n",
       "         [202,  99, 238],\n",
       "         ...,\n",
       "         [ 62,  24, 114],\n",
       "         [ 46,   5, 103],\n",
       "         [ 44,   9,  89]],\n",
       " \n",
       "        [[175, 100, 238],\n",
       "         [191, 109, 246],\n",
       "         [214,  96, 238],\n",
       "         ...,\n",
       "         [ 29,  13,  74],\n",
       "         [ 44,  25,  74],\n",
       "         [ 42,  17,  73]]], dtype=uint8)\n",
       " orig_shape: (480, 640)\n",
       " path: '/root/autodl-tmp/000000039769.jpg'\n",
       " probs: None\n",
       " save_dir: 'runs/detect/predict'\n",
       " speed: {'preprocess': 5.167722702026367, 'inference': 155.32279014587402, 'postprocess': 41.43953323364258}]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from ultralytics import YOLOv10\n",
    "\n",
    "model = YOLOv10.from_pretrained('jameslahm/yolov10x')\n",
    "source = 'http://images.cocodataset.org/val2017/000000039769.jpg'\n",
    "model.predict(source=source, save=True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "911f0a4f-4b9a-4129-a4a3-46ac00e1adce",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
